/**
 * @param {string} password
 * @param {number} target
 * @return {string}
 */
// 还是利用整体反转，再子串反转得到。
var dynamicPassword = function(password, target) {
    let str = Array.from(password);
    reverse(str,0,str.length-1);
    reverse(str,0,str.length-1-target);
    reverse(str,str.length-target,str.length-1)
    return str.join("")
};

 function reverse(strArr, start, end) {
   let left = start;
   let right = end;
 
   while(left < right) {
     // 交换
     [strArr[left], strArr[right]] = [strArr[right], strArr[left]];
     left++;
     right--;
   }
 }